<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <title>床位详情</title>
    <div th:insert="user/common::head"></div>
</head>

<body class="">
    <div class="wrapper ">
        <div th:insert="~{user/common::sidebar(active='inpatientward_list.html')}"></div>
        <div class="main-panel">
            <!-- Navbar导航栏 -->
            <nav th:replace="~{user/common::navbar}"></nav>
            <!-- End Navbar -->
            <div class="panel-header panel-header-sm">
            </div>
            <div class="content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title" th:text="${inpatientWardId+'号房间 床位详情'}" style="display: inline">XX号房间床位详情</h4>
                                <button class="btn-danger btn text-white float-right"  data-toggle="modal" data-target="#deleteCheckModal" style="margin-right: 2rem">删除病房</button>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table">
                                        <thead class="text-primary">
                                            <th>
                                                房间号
                                            </th>
                                            <th>
                                                床位号
                                            </th>
                                            <th>
                                                当前状态
                                            </th>
                                            <th>
                                                患者名称
                                            </th>
                                            <th>
                                                入住日期
                                            </th>
                                            <th>
                                                操作
                                            </th>

                                        </thead>
                                        <tbody>
                                            <p th:if="${bedInfos.isEmpty()}">该房间暂无床位！</p>
                                            <tr th:each="map,index:${bedInfos}" th:style="${map.get('bed_state')==1?'background-color: lightgray':''}">
                                                <td id="inpatientWardId" th:text="${inpatientWardId}">
                                                    房间号
                                                </td>
                                                <td th:text="${map.get('bed_id')}">
                                                    床位号
                                                </td>
                                                <td th:text="${map.get('bed_state')==1?'已占用':'空闲中'}">
                                                    当前状态
                                                </td>
                                                <td th:text="${map.get('patient_name')==null?'无':map.get('patient_name')}">
                                                    患者名称
                                                </td>
                                                <td th:text="${map.get('in_date')==null?'无':#dates.format(map.get('in_date'),'yyyy-MM-dd')}">
                                                    入住日期
                                                </td>
                                                <td>
                                                    <a class="btn btn-warning text-white btn-sm" th:if="${map.get('bed_state')==0}" th:href="@{/deleteBedByBedId/}+${map.get('inpatientward_id')}+'/'+${map.get('bed_id')}">移除</a>
                                                    <a class="btn btn-primary btn-sm text-white" th:if="${map.get('bed_state')==1}" th:href="@{/patient/info/}+${map.get('patient_id')}">详情</a>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <a class="btn-primary btn btn-lg text-white float-left" th:href="@{/toInpatientwardList}">返回</a>
                        <a class="btn-primary btn btn-lg text-white float-right" onclick="addBed()">新增床位</a>
                    </div>
                </div>
            </div>


            <!--底部footer-->
            <footer th:replace="~{user/common::footer}"></footer>
        </div>
    </div>

</body>

<!--确认删除Modal框-->
<div class="modal fade shadow-none p-3 mb-5 rounded" id="deleteCheckModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content" style="margin-top: 15rem">
            <div class="modal-header">
                <h5 class="modal-title">确认删除?</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body"><span>该操作会删除该病房下的所有床位!</span></div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">返回</button>
                <button onclick="deleteInpatientWard()" class="btn btn-danger text-white">确认删除</button>
            </div>
        </div>
    </div>
</div>


<script>
    function addBed(){
        var inpatientWardId = [[${inpatientWardId}]]
        $.ajax({
            sync:false,
            url:'/addBedByInpatientWardId',
            data: {'inpatientWardId':inpatientWardId},
            method:'get',
            dataType:'text',
            success:function(result){
                if(result==='添加成功!'){
                    window.location.reload();
                    demo.showNotification('success',result);
                    return;
                }
                demo.showNotification('danger',result);
            }
        })
    }

    function deleteInpatientWard(){
        var inpatientWardId = [[${inpatientWardId}]]
        $.ajax({
            sync:false,
            url:'/inpatientward/delete',
            data: {'inpatientWardId':inpatientWardId},
            method:'get',
            dataType:'text',
            success:function(result){
                if(result==='删除成功!'){
                    demo.showNotification('success',result);
                    setTimeout(function (){
                        window.location = '/toInpatientwardList';
                    },1000)
                    return;
                }
                demo.showNotification('danger',result);
            }
        })

    }
</script>
<!--通用footerJs-->
<script th:replace="~{user/common::footerJs}"></script>

</html>
